<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:property value="formBean.order.order_type_ws"/> <s:property value="formBean.order.order_Status_s"/></title>
<%@ include file="../../common/Style.jsp"%>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/inventory-order.js?v=4.18"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/HtmlTable.js"></script>
<script src='http://127.0.0.1:8000/CLodopfuncs.js'></script>
<script src='http://127.0.0.1:18000/CLodopfuncs.js'></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/conf_files/js/lodop/headLodop.js?v=10.29"></script>
<script type="text/javascript">
var baseurl = "<%=request.getContextPath()%>";

//the index is depends on the preview or not
<s:if test="formBean.isPreview == true">
index = parseInt("<s:property value='formBean.order.product_List.size()'/>");
</s:if><s:else>
index = parseInt("<s:property value='formBean.order.product_Set.size()'/>");
</s:else>

function saveToDraft(){
	calculateTotal();

	if (validateForm()){
		$.messager.progress({
			title : '提示',
			text : '数据处理中，请稍后....'
		});
		var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!saveToDraft";
		var params=$("#inventoryOrderForm").serialize();  
		$.post(url,params, saveOrderBackProcess,"json");	
	}
}
function saveOrderBackProcess(data){
	$.messager.progress('close');
    var response = data;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		$.messager.alert({
			title: '成功',
			closable: false,
			msg: '单据保存成功',
			fn: function(){
				if (response.action == TYPE_SALES_ORDER_W)
					location.href = "<%=request.getContextPath()%>/action/inventoryOrder!create";
				else if (response.action == TYPE_SALES_RETURN_ORDER_W)
					location.href = "<%=request.getContextPath()%>/action/inventoryOrder!createReturnOrder";
				else 
					parent.closeTab();
			}
		});
    }
		
}


/**
 * once acct finish the edit and save
 */
function acctSave(){
	calculateTotal();

	if (validateForm()){
		$.messager.progress({
			title : '提示',
			text : '数据处理中，请稍后....'
		});
		var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!acctSave";
		var params=$("#inventoryOrderForm").serialize();  
		$.post(url,params, acctSaveBackProcess,"json");	
	}
}
function acctSaveBackProcess(data){
	$.messager.progress('close');
    var response = data;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		var url = "<%=request.getContextPath()%>/action/inventoryOrder!loadOrder?formBean.order.order_ID=" + response.returnValue;
		window.location.href = url;
    }
		
}


/**
 * to submit the order to account
 仓库提交单据给会计
 */
function submitOrder(){
	calculateTotal();
	
	if (validateForm()){
		$.messager.progress({
			title : '提示',
			text : '数据处理中，请稍后....'
		});
		var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!save";
		var params=$("#inventoryOrderForm").serialize();  
		$.post(url,params, saveOrderBackProcess,"json");	
	}
}



/**
 * 下载品类配货单
 */
function downloadOrder(){
	
	var msg = "请确认，你在下载配货单前 没有修改单据 或者已经保存了修改项目";
	var url = "<%=request.getContextPath()%>/action/exportInventoryOrToExcel!downloadOrder";
	$.messager.confirm('确认', msg, function(r){
		if (r){
	   document.inventoryOrderForm.action = url;
	   document.inventoryOrderForm.submit();	
		}
	});
}

/**
 * PDA单据打印
 */
function printOrder(){	
	var isCheck = true;
	var isCheckMsg = "";
	
	var custUser = $("#custName").val();
	var keeperUser = $("#keeper_id").combobox('getValue');
	var scannerUser = $("#scanner_id").combobox('getValue');
	var counterUser = $("#counter_id").combobox('getValue');
	if(custUser == "" || custUser == null){
		isCheck = false;
		isCheckMsg = "客户姓名为空"
	}else if(keeperUser == 0){
		isCheck = false;
		isCheckMsg = "单据输入人员为空"
	}else if(scannerUser == 0){
		isCheck = false;
		isCheckMsg = "单据扫描人员为空"
	}else if(counterUser == 0){
		isCheck = false;
		isCheckMsg = "单据点数人员为空"
	}
	
	if(isCheck){
		var msg = "请确认，你在下载配货单前 没有修改单据 或者已经保存了修改项目";
		$.messager.confirm('确认', msg, function(r){
			if (r){			
		   	 var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!printPDAorder";
			 var params=$("#inventoryOrderForm").serialize();  
			 $.post(url,params, printPDAorderBackProcess,"json");	
			}
		});
	}else{		
		  $.messager.alert('打印提示',isCheckMsg,'warning');
	}

	
	
	

}

function printPDAorderBackProcess(data){
	$.messager.progress('close');
    var response = data;
	var returnCode = response.returnCode;
	var info = response.returnValue.inventoryOrder;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		if(info == null){
			$.messager.alert('错误', '打印错误', 'error');
		}else{
			printPDA(info);
		}		
    }	
}

/**
 * 下载品牌配货单
 */
function downloadOrderByBrand(){
	var url = "<%=request.getContextPath()%>/action/exportInventoryOrToExcel!downloadOrder?formBean.downloadOrderType=1";
	var msg = "请确认，你在下载配货单前 没有修改单据 或者已经保存了修改项目";
	$.messager.confirm('确认', msg, function(r){
		if (r){
	   	document.inventoryOrderForm.action = url;
	   	document.inventoryOrderForm.submit();	
		}
	});
}
function printPOSOrder(){
	var msg = "请确认，你在打印pos小票配货单前 没有修改单据 或者已经保存了修改项目";
	$.messager.confirm('确认', msg, function(r){
		if (r){
		    printPOSOrderToPrinter();	
		}
	});
}

function exportBarcodeToExcel(){
	var url = "<%=request.getContextPath()%>/action/exportInventoryOrToExcel!ExportJinSuanOrder";

	var msg = "请确认，你在下载订单条码前 没有修改单据 或者已经保存了修改项目";
	
	$.messager.confirm('确认', msg, function(r){
		if (r){
	   			document.inventoryOrderForm.action = url;
	   			document.inventoryOrderForm.submit();	
		}
	});
}
function deleteOrder(){
	$.modalDialog({
		title : '授权删除单据',
		width : 330,
		height : 180,
		modal : true,
		href : '<%=request.getContextPath()%>/jsp/headQ/inventory/ConfirmDelete.jsp',
		buttons : [ {
			text : '授权删除',
			handler : function() {
				confirmDelete(); 
			}
		} ]
		});
}
function checkDaimaiMaiduan(){

	if ($("#isMaiduan").prop("checked") && $("#isDaimai").prop("checked") ){
		$.messager.alert('错误', '单据不能同时为 代卖 和 买断,否则会影响报表数据', 'error');
	}
}
$(document).ready(function(){
	$("#custName").focus();
	parent.$.messager.progress('close'); 
	jQuery.excel('excelTable');
	$("#org_table tr").mouseover(function(){      
		$(this).addClass("over");}).mouseout(function(){    
		$(this).removeClass("over");}); 
});
function viewClientInfor(rowId){
  	 var url = "<%=request.getContextPath()%>/action/inventoryOrderJSON!checkClientInventory";
	 var params="formBean.order.cust.id=" + $("#clientID").val() + "&formBean.barcode=" + $("#barcode" + rowId).val() ;  
	 $.post(url,params, viewClientInforBackProcess,"json");	
}
function viewClientInforBackProcess(data){
    var response = data;
	var returnCode = response.returnCode;
	if (returnCode != SUCCESS)
		$.messager.alert('错误', response.message, 'error');
	else {
		$.messager.alert('客户库存信息', response.message, 'infor');	
    }
}
</script>

</head>
<body>

<s:form action="/action/inventoryOrder!previewOrder" method="POST" name="inventoryOrderForm"  id="inventoryOrderForm" theme="simple" enctype="multipart/form-data">
 <s:hidden name="formBean.order.order_ID"  id="orderId"/>
 <s:hidden name="formBean.order.order_type" id="orderType"/>
 <s:hidden name="formBean.order.order_Status"/>
 <s:hidden name="formBean.order.importTimes"/>
 <s:hidden name="formBean.order.pdaScanner.user_id"/>
 <table cellpadding="0" border="0" cellspacing="0"  style="width: 100%" align="center" class="OuterTable">
	<tr class="title">
	     <td colspan="7"><s:if test="formBean.isPreview == true">预览</s:if>
	     <s:if test="formBean.order.order_type == 1">
	          <font style="color: #EEB4B4; font-size: 16px;"><s:property value="formBean.order.order_type_ws"/> </font>
	     </s:if><s:else>
	     	<font style="color: mediumseagreen; font-size: 16px;">  <s:property value="formBean.order.order_type_ws"/></font>
	     </s:else>
	     <s:property value="formBean.order.order_Status_s"/></td>
	</tr>
    
	<tr height="10">
	     <td colspan="7"><hr/></td>
	</tr>

	<%@ include file="../include/EditInventorySalesOrderDetail.jsp"%>
    <s:if test="formBean.isPreview == true">
      <tr height="10">
	  	     <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" onclick="importFile();">导入文件</a>&nbsp;
			     <a type="button" class="easyui-linkbutton" onclick="submitOrder();">单据提交</a></td>			 					 		
			 <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" data-options="iconCls:'icon-save'"   onclick="saveToDraft();">存入草稿</a>
				 <a type="button" href="#" class="easyui-linkbutton"  onclick="calculateTotal();">重新计算</a></td>			 					 		
			 <td>排序<input type="checkbox" name="formBean.sorting" value="true"/></td>			 					 		
			 <td>代卖<input type="checkbox" id="isDaimai" name="formBean.order.isDaimai"  value="1" <s:if test="formBean.order.isDaimai == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			           买断<input type="checkbox"  id="isMaiduan" name="formBean.order.isMaiduan" value="1" <s:if test="formBean.order.isMaiduan == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			 	  调货<input type="checkbox" name="formBean.order.isTransfer" value="1"  <s:if test="formBean.order.isTransfer == 1">checked</s:if>/>
			 </td>
			 <td>&nbsp;</td>	
	  </tr>
    </s:if><s:elseif test="formBean.order.order_Status==0">
	  <tr height="10">
	  	     <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" onclick="importFile();">导入文件</a>&nbsp;
			     <a type="button" class="easyui-linkbutton" onclick="submitOrder();">单据提交</a></td>			 					 		
			 <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" data-options="iconCls:'icon-save'"   onclick="saveToDraft();">存入草稿</a>
				 <a type="button" href="#" class="easyui-linkbutton"  onclick="calculateTotal();">重新计算</a></td>			 					 		
			 <td>排序<input type="checkbox" name="formBean.sorting" value="true"/></td>			 					 		
			 <td>代卖<input type="checkbox" id="isDaimai" name="formBean.order.isDaimai"  value="1" <s:if test="formBean.order.isDaimai == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			          买断<input type="checkbox"  id="isMaiduan" name="formBean.order.isMaiduan" value="1" <s:if test="formBean.order.isMaiduan == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			         调货<input type="checkbox" name="formBean.order.isTransfer" value="1"  <s:if test="formBean.order.isTransfer == 1">checked</s:if>/></td>
			 <td></td>	
	  </tr>
	</s:elseif><s:elseif test="formBean.order.order_Status==9">
	  <tr height="10">
	  	     <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" onclick="importFile();">导入文件</a>&nbsp; <a type="button" class="easyui-linkbutton" onclick="submitOrder();">单据提交</a></td>			 					 		
			 <td><a type="button" class="easyui-linkbutton" onclick="exportBarcodeToExcel();">条码标签导出</a></td>
			 <td><a type="button" class="easyui-linkbutton" data-options="iconCls:'icon-save'"   onclick="saveToDraft();">存入草稿</a>
				 <a type="button" href="#" class="easyui-linkbutton"  onclick="calculateTotal();">重新计算</a></td>			 					 		
			 <td>排序<input type="checkbox" name="formBean.sorting" value="true"/></td>
			 <td>代卖<input type="checkbox" id="isDaimai" name="formBean.order.isDaimai"  value="1" <s:if test="formBean.order.isDaimai == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			          买断<input type="checkbox"  id="isMaiduan" name="formBean.order.isMaiduan" value="1" <s:if test="formBean.order.isMaiduan == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			     调货<input type="checkbox" name="formBean.order.isTransfer" value="1"  <s:if test="formBean.order.isTransfer == 1">checked</s:if>/>
			     <a type="button" class="easyui-linkbutton" onclick="deleteOrder();">删除订单</a></td>			 					 		
			 <td><a type="button" class="easyui-linkbutton" onclick="printOrder();">打印配货单</a>
			 <a type="button" class="easyui-linkbutton" onclick="downloadOrder();">下载品类配货单</a>
			     <a type="button" class="easyui-linkbutton" onclick="downloadOrderByBrand();">下载品牌配货单</a></td>	
	  </tr>
	</s:elseif><s:elseif test="#session.LOGIN_USER.containFunction('inventoryOrder!acctUpdate') || #session.LOGIN_USER.roleType == 99">
	  <tr height="10">
	         <td>&nbsp;</td>
	  	     <td>&nbsp;</td>
			 <td><a type="button" class="easyui-linkbutton" onclick="exportBarcodeToExcel();">条码标签导出</a></td>			 					 		
			 <td><a type="button" href="#" class="easyui-linkbutton"  onclick="calculateTotal();">重新计算</a></td>
			 <td><a type="button" class="easyui-linkbutton" onclick="acctSave();">保存单据</a></td>			 					 					 					 		
			 <td>排序<input type="checkbox" name="formBean.sorting" value="true"/>
			          代卖<input type="checkbox" id="isDaimai" name="formBean.order.isDaimai" value="1" <s:if test="formBean.order.isDaimai == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			          买断<input type="checkbox" id="isMaiduan" name="formBean.order.isMaiduan" value="1"  <s:if test="formBean.order.isMaiduan == 1">checked</s:if> onchange="checkDaimaiMaiduan();"/>
			          调货<input type="checkbox" name="formBean.order.isTransfer" value="1"  <s:if test="formBean.order.isTransfer == 1">checked</s:if>/></td>
			 <td><a type="button" class="easyui-linkbutton" onclick="printOrder();">打印配货单</a>
			 <a type="button" class="easyui-linkbutton" onclick="downloadOrder();">下载品类配货单</a>
			     <a type="button" class="easyui-linkbutton" onclick="downloadOrderByBrand();">下载品牌配货单</a></td>	
	  </tr>				 		      
	</s:elseif>
	  <tr height="10">
	     <td colspan="7"><s:fielderror/></td>
	  </tr>  
</table>

</s:form>
<bgsound id="bgs" src="bg.mp3" loop=1>
</body>
</html>